      SUBROUTINE QUIKVIS0A(IDTARG,IERR)
      IMPLICIT REAL*8 (A-H,O-Z)
C
C THIS ROUTINE IS PART OF THE QUIKVIS PROGRAM.  IT READS THE
C OBSERVATION REQUIREMENTS FILE TO DETERMINE OBS REQMTS AND TARGET ID'S.
C THIS INFO CANNOT BE CHANGED EXCEPT BY CHANGING THE DATA FILES PRIOR
C TO EXECUTING QUIKVIS.
C
C
C VARIABLE      DIM       TYPE I/O DESCRIPTION
C --------      ---       ---- --- -----------
C
C IDTARG      MAXTARGS     I*4  O  DESCRIBED IN QUIKVIS(=MAIN) PROLOGUE.
C
C IERR           1         I*4  O  ERROR RETURN FLAG
C                                  =0, NO ERROR
C                                  =OTHERWISE, ERROR.
C
C***********************************************************************
C
C BY C PETRUZZO/GFSC/742.   2/86.
C       MODIFIED....
C
C***********************************************************************
C
C OBS REQMTS PERMITTED ARE:
C   ORBIT NIGHT
C   VELOCITY VECTOR AVOIDANCE
C   TARGET/ZENITH MAX SEPARATION
C   BRIGHT AND DARK EARTH LIMB AVOIDANCE, BUT BOTH OR NEITHER MUST
C     BE SPECIFIED AND THEY MUST BE EQUAL.
C
C
      INCLUDE 'QUIKVIS.INC'
C
      PARAMETER MAXREQEXP=5
      PARAMETER MAXREQTGT=1
      PARAMETER MAXEXP=1
      PARAMETER MAXTGT=MAXTARGS   ! MAXTARGS IS SET IN QUIKVIS.INC
C
      REAL*8 REQEXP(2,MAXREQEXP,MAXEXP)
      REAL*8 REQTGT(MAXREQTGT,MAXTGT,MAXEXP)
      CHARACTER*8 EXPNAME(MAXEXP)/'ALL'/
      INTEGER NUMTGT(MAXEXP)
      INTEGER KEYREQEXP(MAXREQEXP)/2,7,8,9,10/
C
C
      INTEGER*4 IDTARG(MAXTARGS),IDTEMP(MAXTARGS)
C
      LOGICAL OKID
      INTEGER*2 IORD(MAXTARGS)
C
      IERR = 0
C
C
      CALL QUIKVIS999(-1,R8DATA,I4DATA,L4DATA)
C
C
C *****************************************
C *  GET INFO FROM THE REQUIREMENTS FILE  *
C *****************************************
C
C LOAD ID ARRAY WITH ZEROS
C
      CALL MTXSETI4(IDTARG,0,MAXTARGS,1)
C
C READ THE FILE
C
      CALL RDREQMT(LUOBSREQ,EXPNAME,
     *      MAXEXP,MAXTGT,MAXREQEXP,MAXREQTGT,
     *      KEYREQEXP,REQEXP,REQTGT,NUMEXP,NUMTGT,0,LUPRINT,LUERR,IERR)
      IF(IERR.NE.0) GO TO 9999
C
C
C *******************************
C * SET SKY SURVEY ON/OFF FLAG  *
C *******************************
C
C SET THE FLAG INDICATING WHETHER THE SKY SURVEY OPTION IS ACTIVE OR
C INDIVIDUAL TARGETS ARE TO BE PROCESSED.  IF REQUIREMENTS FILE HAS
C SPECIFIED NO TARGETS, THEN A SKY SURVEY IS DONE.
C
      DOSURVEY = NUMTGT(1).EQ.0
C
C
C *********************
C *  SET TARGET ID'S  *
C *********************
C
      IF(.NOT.DOSURVEY) THEN     ! INDIVIDUAL TARGETS WERE SPECIFIED
        KTARGS = NUMTGT(1)
        IF(KTARGS.GT.0) THEN
          DO I=1,KTARGS
            IDTARG(I) = JIDNNT(REQTGT(1,I,1))
            END DO
          END IF
      ELSE                       ! USER WANTS THE 'SURVEY' OPTION
        KTARGS = NRASURVEY * NDECSURVEY
        DO I=1,KTARGS
          IDTARG(I) = I
          END DO
        END IF
C
C
C *********************************************
C *  SET OBSERVATION REQUIREMENTS PARAMETERS  *
C *********************************************
C
C SET ORBIT NIGHT FLAG, DOREQMT(2)
C
      KTEMP = JIDNNT(REQEXP(1,1,1))
      IF(KTEMP.EQ.0 .OR. KTEMP.EQ.1) THEN  ! = IGNORE OR NIGHT-ONLY ?
        DOREQMT(2) = KTEMP.EQ.1
        NEEDTIME = NEEDTIME .OR. DOREQMT(2)
      ELSE
        IERR = 1
        WRITE(LUERR,9001)
     *    ' QUIKVIS CANNOT DO ORBIT-DAY-ONLY REQUIREMENT.'
        GO TO 9999
        END IF
C
C
C SET EARTH AVOIDANCE ANGLE AND OCCULTATION REQUIREMENT FLAG, DOREQMT(1)
C
      DOREQMT(1) = .TRUE.
      IF(REQEXP(1,2,1).EQ.REQEXP(1,3,1)) THEN
        EAVOID = REQEXP(1,2,1)
      ELSE
        IERR = 1
        WRITE(LUERR,9001)
     *     ' QUIKVIS REQUIRES EQUAL VALUES FOR BRIGHT AND DARK ' //
     *        'HORIZON AVOIDANCE.'
        GO TO 9999
        END IF
C
      IF(EAVOID.LT.0.D0) THEN
        IERR = 1
        WRITE(LUERR,9001)
     *    ' EARTH HORIZON AVOIDANCE ANGLE MUST BE ZERO OR POSITIVE.'
        GO TO 9999
        END IF
C
C
C SET VELOCITY VECTOR AVOIDANCE ANGLE AND REQUIREMENT FLAG, DOREQMT(3).
C
      VAVOID = REQEXP(1,4,1)
      DOREQMT(3) = VAVOID.GT.0.D0
C
      IF(VAVOID.LT.0.D0 .OR. VAVOID.GT.PI) THEN
        IERR = 1
        WRITE(LUERR,9001)
     *    ' VELOCITY VECTOR AVOIDANCE ANGLE MUST BE IN ' //
     *          '0 TO 180 DEGREE RANGE.'
        GO TO 9999
        END IF
C
C
C SET MAX ZENITH/TARGET SEPARATION ANGLE AND REQ'MT FLAG, DOREQMT(4).
C
      ZMAXSEP = REQEXP(1,5,1)
      DOREQMT(4) = ZMAXSEP .LT. 179.999D0/DEGRAD
C
      IF(ZMAXSEP.LT.0.D0 .OR. ZMAXSEP.GT.PI) THEN
        IERR = 1
        WRITE(LUERR,9001)
     *    ' ZENITH MAX SEPARATION ANGLE MUST BE IN ' //
     *          '0 TO 180 DEGREE RANGE.'
        GO TO 9999
        END IF
C
C
C ******************
C *  HOUSEKEEPING  *
C ******************
C
C
C VERIFY THAT THERE ARE ONE OR MORE TARGETS WITH POSITIVE ID'S
C
      OKID = .FALSE.
      ITARG = 0
      DO WHILE (.NOT.OKID .AND. ITARG.LT.MAXTARGS)
        ITARG = ITARG + 1
        OKID = IDTARG(ITARG).GT.0
        END DO
C
C    ERROR CHECK.
      IF(.NOT.OKID) THEN
        IERR = 1
        WRITE(LUERR,7701)
        IF(LUPROMPT.NE.LUERR) WRITE(LUPROMPT,7701)
 7701   FORMAT(/,
     *   ' QUIKVIS2 ERROR. NO POSITIVE ID''S HAVE BEEN ENTERED.')
        GO TO 9999
        END IF
C
C ELIMINATE DUPLICATE TARGET ID'S
C
      DO ITARG = 2,MAXTARGS
        IF(IDTARG(ITARG).GT.0) THEN
          ID = IDTARG(ITARG)
          DO JTARG = 1,ITARG-1
            IF( ID.EQ.IDTARG(JTARG) ) IDTARG(JTARG) = 0
            END DO
          END IF
        END DO
C
C SHIFT TARGET ID'S TO LOWER INDEXED ELEMENTS. COUNT NUMBER OF TARGETS.
C
      NUMTARGS = 0
      DO ITARG=1,MAXTARGS
        IF(IDTARG(ITARG).GT.0) THEN
          NUMTARGS = NUMTARGS + 1
          IDTARG(NUMTARGS) = IDTARG(ITARG)
          END IF
        END DO
C    ZERO OUT THE REST OF THE ID ARRAY. (FOR NEATER HOUSEKEEPING)
      IF(NUMTARGS.LT.MAXTARGS) THEN
        DO ITARG = NUMTARGS+1,MAXTARGS
          IDTARG(ITARG) = 0
          END DO
        END IF
C
C PUT TARGET ID'S IN ASCENDING ORDER SO THEY ARE EASY TO FIND IN THE
C OUTPUT
C
      CALL ORDER(IDTARG,NUMTARGS,IORD)
      DO I=1,NUMTARGS
        IDTEMP(I) = IDTARG(I)
        END DO
      DO I=1,NUMTARGS
        IDTARG(I) = IDTEMP(IORD(I))
        END DO
C
C
 9999 CONTINUE
C
C WRAP UP. STORE DATA IN QUIKVIS999 ARRAYS FOR RETRIEVAL ELSEWHERE.
C
      CALL QUIKVIS999(1,R8DATA,I4DATA,L4DATA)
C
      RETURN
 9001 FORMAT(/,
     *      ' QUIKVIS0A. OBS REQMT ERROR.'/,  A/,
     *      ' CHANGE THE REQUIREMENTS FILE.'/)
      END
